package study.java.jdk.jdk8._1_stream.parallel;

import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.RandomUtil;
import lombok.Data;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;

import java.util.List;
import java.util.stream.Collectors;

@Slf4j
public class UserClient {

    public static List<UserData> getUserLt(List<String> userIdLt) {
        log.info(">>>>>> {}", userIdLt);
        return userIdLt.stream().map(e ->
                new UserData().setUserId(e)
                        .setUserName("wangzhj" + e))
                .collect(Collectors.toList());
    }

    public static UserData getUser(String userId) {
        int seed = RandomUtil.randomInt(10);
        int sec = seed * 1000;
        //log.info("user[{}] start", userId);
        ThreadUtil.sleep(sec);
        log.info("user[{}] cost time [{}] s", userId, seed);
        UserData user = new UserData();
        user.setUserId(userId);
        return user;
    }

    @Accessors(chain = true)
    @Data
    public static class UserData {
        private String userId;
        private String userName;
    }
}
